package com.hbsx.why.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hbsx.why.R;
import com.hbsx.why.ui.WebViewActivity;
import com.hbsx.why.ui.find.ImageActivity;
import com.hbsx.why.utils.LogUtils;

import java.util.List;

/**
 * ListAdapter
 * Created by XiaoWei on 2015-11-14.
 */
public class FindListAdapter extends BaseListAdapter<String> {
    private Context context;

    public FindListAdapter(Context context, List<String> objects) {
        super(context, objects);
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            if (getItemViewType(position) == 0) {
                convertView = ((Activity) (mContext)).getLayoutInflater().inflate(R.layout.layout_has_no_data, parent, false);
                holder.noDataRootLayout = (LinearLayout) convertView.findViewById(R.id.root_layout);
            } else {
                convertView = ((Activity) (mContext)).getLayoutInflater().inflate(R.layout.item_find_list_view, parent, false);
                holder.imageView = (ImageView) convertView.findViewById(R.id.find_image_view);
                holder.nameText = (TextView) convertView.findViewById(R.id.name_text);
                holder.watchNumText = (TextView) convertView.findViewById(R.id.watch_num_Text);
            }
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        switch (mDataList.get(position)) {
            case "0数据刷新--0":
                LogUtils.loge("+++++++++++>" + mDataList.get(position));
                holder.imageView.setImageResource(R.mipmap.demo_huifengwanyun);
                holder.nameText.setText("徽风皖韵");
                holder.watchNumText.setText("1824");
                holder.imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        context.startActivity(new Intent(context, ImageActivity.class));
                    }
                });
                break;
            case "0数据刷新--1":
                LogUtils.loge("+++++++++++>" + mDataList.get(position));
                holder.nameText.setText("安庆·黄梅戏");
                holder.watchNumText.setText("1028");
                holder.imageView.setImageResource(R.mipmap.find_huangmeixi);
                break;
            case "0数据刷新--2":
                LogUtils.loge("+++++++++++>" + mDataList.get(position));
                holder.nameText.setText("仙境黄山");
                holder.watchNumText.setText("1528");
                holder.imageView.setImageResource(R.mipmap.find_huangshan);
                break;
            case "0数据刷新--3":
                LogUtils.loge("+++++++++++>" + mDataList.get(position));
                holder.nameText.setText("悦·书房");
                holder.watchNumText.setText("2028");
                holder.imageView.setImageResource(R.mipmap.find_yueshufang);
                break;
            default:
                LogUtils.loge("+++++++++++>" + mDataList.get(position));
                holder.imageView.setImageResource(R.mipmap.find_huiwenhua);
                break;
        }

//        if (hasNoData) {
//            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(getScreenWidth(), getScreenHeight() * 2 / 3);
//            holder.noDataRootLayout.setLayoutParams(lp);
//        } else {
////            holder.textView.setText(mDataList.get(position));
//            switch (mDataList.get(position)) {
//                case "0数据刷新--0":
//                    LogUtils.loge("+++++++++++>" + mDataList.get(position));
//                    holder.imageView.setImageResource(R.mipmap.find_huiwenhua);
//                    break;
//                case "0数据刷新--1":
//                    LogUtils.loge("+++++++++++>" + mDataList.get(position));
//                    holder.imageView.setImageResource(R.mipmap.find_huangmeixi);
//                    break;
//                case "0数据刷新--2":
//                    LogUtils.loge("+++++++++++>" + mDataList.get(position));
//                    holder.imageView.setImageResource(R.mipmap.find_huiwenhua);
//                    break;
//                case "0数据刷新--3":
//                    LogUtils.loge("+++++++++++>" + mDataList.get(position));
//                    holder.imageView.setImageResource(R.mipmap.find_yueshufang);
//                    break;
//                default:
//                    LogUtils.loge("+++++++++++>" + mDataList.get(position));
//                    holder.imageView.setImageResource(R.mipmap.find_huiwenhua);
//                    break;
//
//            }
//        }

        return convertView;
    }

    private static final class ViewHolder {
        ImageView imageView;
        TextView nameText, watchNumText;
        LinearLayout noDataRootLayout;
    }

    private int getScreenWidth() {
        DisplayMetrics displayMetric = Resources.getSystem().getDisplayMetrics();
        return displayMetric.widthPixels;
    }

    private int getScreenHeight() {
        DisplayMetrics displayMetric = Resources.getSystem().getDisplayMetrics();
        return displayMetric.heightPixels;
    }

}
